package com.bachongLightNovel.works.controller;

import com.bachongLightNovel.model.pojo.works.Novel;
import com.bachongLightNovel.model.pojo.works.NovelDetails;
import com.bachongLightNovel.model.vo.works.NovelRecordVo;
import com.bachongLightNovel.model.vo.works.NovelVo;
import com.bachongLightNovel.result.Result;
import com.bachongLightNovel.works.service.WorksNovelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author vermouth
 */

@RestController
@RequestMapping("/api/works/novel")
@Slf4j
public class WorksNovelController {

    @Autowired
    private WorksNovelService worksNovelService;

    /**
     * 新建小说基本信息
     * @param novel:
     * @return Result
     * @author vermouth
     */
    @PostMapping("save")
    public Result saveNovel(@RequestBody Novel novel){
        log.info("新建小说基本信息：{}",novel);
        worksNovelService.saveNovel(novel);
        return Result.success();
    }

    /**
     * 查询当前登录用户的小说集合
     * @param :
     * @return Result
     * @author vermouth
     */
    @GetMapping("current-user-list")
    public Result CurrentUserNovelList(){
        log.info("查询当前登录用户的小说集合");
        List<Novel> novelList=worksNovelService.CurrentUserList();
        return Result.success(novelList);
    }

    /**
     * 根据小说id获取小说的基本信息
     * @param id:
     * @return Result
     * @author vermouth
     */
    @GetMapping("get-novel/{id}")
    public Result getNovelById(@PathVariable Long id){
        log.info("根据小说id获取小说的基本信息：{}",id);
        NovelVo vo=worksNovelService.getNovelById(id);
        return Result.success(vo);
    }

    /**
     * 新增对应小说的小说章节
     * @param novelDetails:
     * @return Result
     * @author vermouth
     */
    @PostMapping("save-detail")
    public Result saveDetail(@RequestBody NovelDetails novelDetails){
        log.info("新增对应小说的小说章节：{}",novelDetails);
        worksNovelService.saveNovelDetail(novelDetails);
        return Result.success();
    }

    /**
     * 删除小说章节
     * @param novelDetails:
     * @return Result
     * @author vermouth
     */
    @DeleteMapping("remove-detail")
    public Result removeNovelDetail(@RequestBody NovelDetails novelDetails){
        log.info("删除小说章节：{}",novelDetails);
        worksNovelService.removeNovelDetail(novelDetails);
        return Result.success();
    }

    /**
     * 新增小说章节内容
     * @param novelDetails: 
     * @return Result
     * @author vermouth
     */      
    @PutMapping("save-content")
    public Result saveDetailContent(@RequestBody NovelDetails novelDetails){
        log.info("新增小说章节内容：{}",novelDetails);
        worksNovelService.saveDetailContent(novelDetails);
        return Result.success();
    }

    /**
     * 根据小说章节id获取小说章节内容
     * @param detailId:
     * @return Result
     * @author vermouth
     */
    @GetMapping("get-content/{detailId}")
    public Result getDetailContent(@PathVariable Long detailId){
        log.info("根据小说章节id获取小说章节内容：{}",detailId);
        NovelDetails novelDetails=worksNovelService.getDetailContent(detailId);
        return Result.success(novelDetails);
    }

    /**
     * 根据小说id删除小说
     * @param novelId:
     * @return Result
     * @author vermouth
     */
    @DeleteMapping("remove/{novelId}")
    public Result removeNovel(@PathVariable Long novelId){
        log.info("根据小说id删除小说：{}",novelId);
        worksNovelService.removeNovel(novelId);
        return Result.success();
    }


    /**
     * 修改小说发布状态
     * @param novelId:
    	 * @param status:
     * @return Result
     * @author vermouth
     */
    @PutMapping("update-status/{novelId}/{status}")
    public Result updateNovelStatus(@PathVariable Long novelId,
                                    @PathVariable Short status){
        log.info("修改小说发布状态：{}",status);
        worksNovelService.updateNovelStatus(novelId,status);
        return Result.success();
    }

    /**
     * 获取当前用户小说提交数据
     * @param :
     * @return Result
     * @author vermouth
     */
    @GetMapping("get-record")
    public Result getCurrentRecord(){
        log.info("获取当前用户小说提交数据");
        List<NovelRecordVo> voList=worksNovelService.getCurrentRecord();
        return Result.success(voList);
    }
}
